package com.yycx.module.admin.provider.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.constants.CommonConstants;
import com.yycx.common.mybatis.base.service.impl.BaseServiceImpl;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.admin.client.entity.BaseUserAccountLogs;
import com.yycx.module.admin.provider.mapper.BaseUserAccountLogsMapper;
import com.yycx.module.admin.provider.service.BaseUserAccountLogsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: zyf
 * @date: 2018/10/24 16:33
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BaseUserAccountLogServiceImpl extends BaseServiceImpl<BaseUserAccountLogsMapper, BaseUserAccountLogs> implements BaseUserAccountLogsService {

    @Override
    public ResultBody beforePageList(CriteriaQuery<BaseUserAccountLogs> cq, BaseUserAccountLogs baseUserAccountLogs, EntityMap requestMap) {
        cq.ne("account", CommonConstants.ROOT);
        cq.like("loginIp", cq.getParams("loginIp"));
        cq.like("account", cq.getParams("account"));
         if (ObjectUtil.isNotNull(cq.getParams("beginDate"))) {
            cq.ge(ObjectUtil.isNotNull(cq.getParams("beginDate")), "DATE_FORMAT(loginTime,'%Y-%m-%d')", cq.getParams("beginDate"));
            cq.le(ObjectUtil.isNotNull(cq.getParams("endDate")), "DATE_FORMAT(loginTime,'%Y-%m-%d')", cq.getParams("endDate"));
        }
        cq.orderByDesc("loginTime");
        return ResultBody.ok();
    }
}
